package com.wudl.flink.hbase.utils;

import com.alibaba.fastjson.JSON;
import com.wudl.flink.hbase.model.User;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.MD5Hash;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author ：wudl
 * @date ：Created in 2021-12-08 23:05
 * @description：
 * @modified By：
 * @version: 1.0
 */

public class RowKeyUtils {


    public static byte[] getRowkey(User User) throws ParseException {
        // 3. 构建ROWKEY
        // 发件人ID1反转
        StringBuilder stringBuilder = new StringBuilder(10);
//        stringBuilder.append("_");
//        stringBuilder.append(10);
//        stringBuilder.append("_");

        // 转换为时间戳
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:MM:ss");
        stringBuilder.append(sdf.parse(User.getCreateTime()).getTime());
        byte[] orginkey = Bytes.toBytes(stringBuilder.toString());
        // 为了避免ROWKEY过长，取前八位
        String md5AsHex = MD5Hash.getMD5AsHex(orginkey).substring(0, 8);
        return Bytes.toBytes(md5AsHex + "_" + stringBuilder.toString());
    }



}
